<template>
  <div class="edit-achieve-container detailsPageBox">

    <div class="detailsMain" id="pdfDom">
      <div class="form-title" style="border:none;padding-top: 0;">
        <span class="icon"></span>
        <span class="text">成果基本信息</span>
      </div>

      <el-form :model="data.form" :inline="true">
        <el-form-item label="成果名称:" class="form-item-width">
          <div>{{ data.form.resultTitle }}</div>
        </el-form-item>
        <el-form-item label="成果所属领域:" class="form-item-width">
          <div>{{ data.form.industryNameOne }}</div>
        </el-form-item>
        <el-form-item label="成果类型:" class="form-item-width">
          <div>{{ data.form.resultTypeName }}</div>
        </el-form-item>
        <el-form-item label="合作方式:" class="form-item-width">
          <div>{{ data.form.resultCooperationName }}</div>
        </el-form-item>
        <el-form-item label="技术成熟度:" class="form-item-width">
          <div>{{ data.form.resultSkillStageName }}</div>
        </el-form-item>
        <el-form-item label="合作金额(万元):" class="form-item-width">
          <div>{{ data.form.resultBudget }}</div>
        </el-form-item>
        <el-form-item label="成果截止日期:" class="form-item-width">
          <div>{{ data.form.resultExpirationDate }}</div>
        </el-form-item>
        <el-form-item label="需求所在地:">
          <div>
            {{ data.form.resultProvinceName + data.form.resultCityName + data.form.resultAreaName +
                data.form.detailAddress
            }}
          </div>
        </el-form-item>
      </el-form>

      <div class="form-title" v-if="data.form.includePatent">
        <span class="icon"></span>
        <span class="text">成果专利信息</span>
      </div>
      <el-form :model="data" v-for="patent in data.patentList">
        <el-form-item label="专利号:">
          <div>{{ patent.pn }}</div>
        </el-form-item>
        <el-form-item label="专利名称:">
          <div class="form-name-title">{{ patent.ttl }}</div>
        </el-form-item>
        <el-form-item label="专利摘要:">
          <div>{{ patent.abst }}</div>
        </el-form-item>
      </el-form>

      <div class="form-title">
        <span class="icon"></span>
        <span class="text">成果详细信息</span>
      </div>
      <el-form :model="data.form">
        <el-form-item label="成果描述:">
          <div v-html="data.form.resultDescribe" class="desc-text"></div>
        </el-form-item>
        <el-form-item label="技术指标:">
          <div v-html="data.form.resultTarget" class="desc-text"></div>
        </el-form-item>
        <el-form-item label="应用案例:">
          <div v-html="data.form.resultCase" class="desc-text"></div>
        </el-form-item>
      </el-form>

      <div class="form-title" v-if="data.imageList.length > 0 || data.fileList.length > 0">
        <span class="icon"></span>
        <span class="text">成果证明材料</span>
      </div>
      <el-form>
        <el-form-item label="图片信息:">
          <div class="img-container">
            <div class="img-content" v-for="img in data.imageList">
              <img :src="img.path" alt="">
            </div>
          </div>
          <img src="" alt="">
        </el-form-item>
        <el-form-item label="附件信息:">
          <div class="file-container">
            <el-upload :file-list="data.fileList" class="upload-demo" :auto-upload="false" :on-preview="clickFile" />
          </div>
        </el-form-item>
      </el-form>

      <div class="form-title">
        <span class="icon"></span>
        <span class="text">成果发布方信息</span>
      </div>
      <el-form :model="data.form" :inline="true">
        <el-form-item label="企业名称:" v-if="data.userVerify.length > 0" class="form-item-width">
          <div>{{ data.userVerify[0].name }}</div>
        </el-form-item>
        <el-form-item label="联系人:" style="width:50%">
          <div>{{ data.form.resultContactPerson }}</div>
        </el-form-item>
        <el-form-item label="统一社会信用代码:" v-if="data.userVerify.length > 0" class="form-item-width">
          <div>{{ data.userVerify[0].card }}</div>
        </el-form-item>
        <el-form-item label="联系电话:" style="width:50%">
          <div>{{ data.form.resultContactPhone }}</div>
        </el-form-item>
        <el-form-item label="企业地址:" v-if="data.userVerify.length > 0" class="form-item-width">
          <div>{{ data.userVerify[0].companyType }}</div>
        </el-form-item>
      </el-form>

    </div>

    <div class="btn-list detailsHandBtn" v-if="props.type == 'check'">
      <el-button size="large" style="width: 100px;height:36px" type="primary" @click="isPassInfo(true)">通过</el-button>
      <el-button size="large" style="width: 100px;height:36px" @click="isPassInfo(false)">拒绝</el-button>
    </div>
    <div class="btn-list detailsHandBtn" v-if="props.type == 'detail' ? true : false">
      <el-button size="large" style="width: 100px;height:36px" type="primary" v-print="'#pdfDom'">导出为PDF</el-button>
      <el-button size="large" style="width: 100px;height:36px" @click="backRoute('Achievement')">返回</el-button>
    </div>

    <el-dialog v-model="data.dialogVisible" width="30%" :before-close="handleClose">
      <template #title>
        <span v-if="data.pass">审核确认</span>
        <span v-else>请填写拒绝原因</span>
      </template>
      <template #default>
        <div v-if="data.pass">你确认《{{ data.form.resultTitle }}》通过审核吗？</div>
        <div v-else>
          <el-input type="textarea" :rows="4" resize="none" v-model="data.refuseInfo"></el-input>
        </div>
      </template>
      <template #footer>
        <span class="dialog-footer">
          <el-button type="primary" @click="pass">确定</el-button>
          <el-button @click="data.dialogVisible = false">取消</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import { onMounted, onUnmounted, reactive } from 'vue'
import { auditAchievementApi, achievementDetailApi } from '@/api/interface/achievement.js'
import { getFileFlowByIdApi } from '@/api/interface/policy.js'
import { textToSensitiveWordApi } from '@/api/interface/algorithm.js'

import { backRoute, fileDownload } from '@/utils/common.js'
import { ElMessage } from 'element-plus'
import { useStore } from 'vuex'
import { useRouter } from 'vue-router'
const store = useStore()
const router = useRouter()

const props = defineProps({
    id: {
        type: String,
    },
    type: {
        type: String,
    },
})

const data = reactive({
  form: {},
  patentList: [],
  userVerify: [],
  dialogVisible: false,
  pass: false,
  refuseInfo: '',
  imageList: [],
  fileList: []
})


onMounted(() => {
  const level = router.currentRoute.value.meta.level
  store.dispatch('setting/setRouterCut', level)
})
onUnmounted(() => {
  store.dispatch('setting/setRouterCut', 2)
})


//获取详细信息
const getAchievementInfo = () => {
  achievementDetailApi({ id: props.id? props.id : sessionStorage.resultId}).then(res => {
    data.form = res.data
    data.userVerify = res.data.userVerify
    data.patentList = res.data.patentList
    res.data.file.forEach(v => {
      if (v.bucket === 'picture') {
        data.imageList.push(v)
      } else {
        v.name = v.fileShowname
        data.fileList.push(v)
      }
    })
  })
}
getAchievementInfo()


//下载文件
const clickFile = (file) => {
  const params = {
    fileId: file.id
  }
  getFileFlowByIdApi(params).then(res => {
    fileDownload(file, res)
  })
}





//是否通过
const isPassInfo = (bool) => {
  data.pass = bool
  data.dialogVisible = true
}
//通过
const pass = async () => {
  // const safe =  await textToSensitiveWordApi(
  //   {
  //     data:data.form.resultTitle + data.form.detailAddress + data.form.resultDescribe + 
  //     data.form.resultTarget + data.form.resultCase + data.form.resultPublishPerson,
  //   }
  // ).then(res => res.data.sensitive_word)
  
  // if (safe.length > 0) {
  //   ElMessage({
  //       message: '含有敏感字符'+ safe.join('，'),
  //       type: 'error',
  //     })
  //   return
  // }
  const params = {
    auditBusinessNum: props.id,
    auditContent: data.pass ? '审核通过' : data.refuseInfo,
    auditType: data.pass ? "SUCCESS" : "BACK",
    userName: store.state.user.userInfo.userName
  }
  auditAchievementApi(JSON.stringify(params)).then(res => {
    if (res.status === 200) {
      data.dialogVisible = false
      ElMessage({
        message: res.message,
        type: 'success',
      })
      backRoute('Achievement')
    }
  })
}
</script>

<style lang="scss" scoped>
.edit-achieve-container {
  padding: 20px;
  :deep(.el-form-item__label) {
    font-weight: 700;
    color: #333;
  }

  .form-item-width {
    width: 40%;
  }

  .el-form-item {
    margin-bottom: 0;
  }

  :deep(.el-form-item__content) {
    font-size: 12px;

    p {
      margin: 0;
    }
  }

  .el-form {
    margin-bottom: 20px;
  }

  .tips {
    color: #f74b33;
    font-size: 14px;
    margin-left: 10px;
  }

  .form-title {
    display: flex;
    align-items: center;
    padding: 20px 0;
    font-size: 16px;
    font-weight: 700;
    border-top: 1px solid #e3e3e3;

    .icon {
      width: 6px;
      height: 16px;
      background-color: #00a2ff;
      margin-right: 6px;
    }

    .text {
      font-size: 16px;
      font-weight: 700;
    }
  }

  :deep(.el-upload--text) {
    display: none;
  }

  :deep(.el-icon--close, .el-icon--upload-success) {
    display: none;
  }

  :deep(.el-icon--upload-success) {
    display: none;
  }

  .img-container {
    width: 100%;
    display: flex;

    .img-content {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 160px;
      height: 160px;
      overflow: hidden;
      border-radius: 8px;
      border: 1px solid #f1f1f1;
      margin-right: 20px;
      margin-bottom: 20px;

      img {
        width: 100%;
      }
    }
  }

  .file-container {
    width: 100%;
  }

  .form-name-title {
    font-weight: 700;
    color: #00a2ff;
  }

  .btn-list {
    padding-top: 20px;
    text-align: center;
    border-top: 1px solid #e3e3e3;
  }
}




</style>